package com.mokio.service.impl;

import com.mokio.entity.Carshop;
import com.mokio.entity.CarshopExample;
import com.mokio.mapper.CarshopMapper;
import com.mokio.service.CarshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: xiaomishop
 * @ClassName CarshopServiceImpl
 * @description:
 * @author: mokio
 * @create: 2024−12-20 18:52
 * @Version 1.0
 **/
@Service
public class CarshopServiceImpl implements CarshopService {

    @Autowired
    CarshopMapper carshopMapper;

    //  微加修改  ===============================================================
    @Override
    public boolean addCarShopOfCarshop(Carshop carshop) {
        //查看有没有
        List<Carshop> carshops = carshopMapper.selectByUIdAndPId(carshop);

        boolean flag = false;

        if (carshops.size()>0) {//下单过该商品
            flag = carshopMapper.updateCarshopsAddOne(carshops.get(0).getCid());
        }else{
            int num = carshopMapper.insert(carshop);
            if (num > 0) {
                flag = true;
            }
        }
        return flag;
    }

    @Override
    public List<Carshop> getAllCarShopByUserId(Integer uid) {
        List<Carshop> carshopList= carshopMapper.getAllCarShopByUserId(uid);
        return carshopList;
    }

    @Override
    public void deleteByCid(int cid) {
        CarshopExample carshopExample = new CarshopExample();
        carshopExample.createCriteria().andCidEqualTo(cid);
        carshopMapper.deleteByExample(carshopExample);
    }
}
